package com.sss.hloster0703;

import java.util.Scanner;

public class TestEx01 {

	public static void main(String[] args) {
		test02();
	}

	private static void test01() {
		try {
			String teachers[] = { "王林", "韩立", "苏铭" };
			for (int i = 0; i < teachers.length; i++) {
				System.out.print(teachers[i] + "   ");
			}

		} catch (Exception e) {
			System.out.println();
			System.out.println("数组下标越界，请修改程序！");
		}
		System.out.println("显示完毕！！");
	}

	private static void test02() {
		try {
			String teachers[] = { "王林", "韩立", "苏铭" };
			for (int i = 0; i < teachers.length; i++) {
				System.out.print(teachers[i] + "   ");
			}
			System.out.println();
			int appleNum = 0;// 苹果数
			int stuNum = 0;// 学生数
			System.out.println("***现在给孩子们分苹果***");
			Scanner input = new Scanner(System.in);
			System.out.print("请输入桌子上有几个苹果：");
			appleNum = input.nextInt();
			System.out.print("请输入班上有几个孩子：");
			stuNum = input.nextInt();
			System.out.println("班上每个孩子分得多少苹果：" + appleNum / stuNum);
			System.out.println("小崽子们很开心！！！！");
		} catch (ArrayIndexOutOfBoundsException e) {// 捕获数组下标越界异常

			System.out.println("数组下标越界，请修改程序！");
		} catch (ArithmeticException e) {                            // 捕获算数异常
			System.out.println("算数异常，请检查程序！！");
		}
		System.out.println("程序执行完毕！！");
	}
}
